/*** 
 * @_______________#########_______________________ 
 * @______________############_____________________ 
 * @______________#############____________________ 
 * @_____________##__###########___________________ 
 * @____________###__######_#####__________________ 
 * @____________###_#######___####_________________ 
 * @___________###__##########_####________________ 
 * @__________####__###########_####_______________ 
 * @________#####___###########__#####_____________ 
 * @_______######___###_########___#####___________ 
 * @_______#####___###___########___######_________ 
 * @______######___###__###########___######_______ 
 * @_____######___####_##############__######______ 
 * @____#######__#####################_#######_____ 
 * @____#######__##############################____ 
 * @___#######__######_#################_#######___ 
 * @___#######__######_######_#########___######___ 
 * @___#######____##__######___######_____######___ 
 * @___#######________######____#####_____#####____ 
 * @____######________#####_____#####_____####_____ 
 * @_____#####________####______#####_____###______ 
 * @______#####______;###________###______#________ 
 * @________##_______####________####______________ 
 * @
 * @Author: ipk518 121206530@qq.com
 * @Date: 2025-03-06 20:00:55
 * @LastEditors: ipk518 121206530@qq.com
 * @LastEditTime: 2025-10-18 11:36:28
 * @FilePath: /etws-sxk2307/src/packetResolver/lxCmdV1/powerConf.cpp
 * @Description: 
 * @************佛祖保佑************
 * @Copyright (c) 2025 by etws@quyujiang, All Rights Reserved. 
 */


#include "Server.h"
#include "lxCmdV1.h"


/**
 * @description: 选通电源
 * @param {cmdDataType*} cmd
 * @param {uint8_t *} cmdData
 * @return {*}
 */
int power_callback_0(struct cmdDataType* cmd,uint8_t * cmdData)
{   
    if(Server::Instance().m_sxk.m_controlReg.m_timingStatus == 0x01){
        qlog_e("雷达正在工作,不能控电");
        return -1;
    } 

    uint8_t devtype = *cmdData;//组件类型
    uint8_t usNRegs = *(cmdData+1);//组件编号
    uint8_t powerstatus = *(cmdData+2);//电源状态


    qlog_n("选通电源:类型=%d,组件号=%d,值=%d.",devtype,usNRegs,powerstatus);
    Server::Instance().m_sxk.powerControl((powerstatus > 0),devtype,usNRegs);
    
    return Server::Instance().responseWeb(cmd);
}

/**
 * @description: 一键控电源
 * @param {cmdDataType*} cmd
 * @param {uint8_t *} cmdData
 * @return {*}
 */
int power_callback_1(struct cmdDataType* cmd,uint8_t * cmdData)
{
    if(Server::Instance().m_sxk.m_controlReg.m_timingStatus == 0x01){
        qlog_e("雷达正在工作,不能控电");
        return -1;
    } 
    uint8_t powerstatus = *cmdData;

    Server::Instance().m_sxk.powerControl((powerstatus > 0),0,0);
    if (powerstatus < 0) { //1、清除AD组件状态.2、准备一键上电后需重新同步
        Server::Instance().m_hrServer->setAlive(AD_Sub_Unit_S,0,false);
        Server::Instance().m_hrServer->setAlive(AD_Sub_Unit_S,1,false);
    }
    return Server::Instance().responseWeb(cmd);
}